package com.qiaofang.housewarehouse.service.compose;

import com.qiaofang.housewarehouse.dao.domain.EsHswhRentalHouse;
import com.qiaofang.housewarehouse.dao.domain.HswhRentalHouse;
import com.qiaofang.housewarehouse.stub.bean.HswhRentalHouseDetailDTO;
import com.qiaofang.housewarehouse.stub.bean.HswhRentalHouseListDTO;
import com.qiaofang.housewarehouse.stub.bean.HswhRentalHouseListEntity;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class HswhRentalHouseCompose {
    public static List<HswhRentalHouseListDTO> composeListDTO(List<HswhRentalHouse> list) throws Exception {
        List<HswhRentalHouseListDTO> dtoList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return dtoList;
        }
        for (HswhRentalHouse DO : list) {
            HswhRentalHouseListDTO dto = new HswhRentalHouseListDTO();
            BeanUtils.copyProperties(DO, dto);
            if (StringUtils.isNotBlank(DO.getImgs())){
                dto.setImg(true);
            }else {
                dto.setImg(false);
            }
            dtoList.add(dto);
        }
        return dtoList;
    }

    public static List<HswhRentalHouseDetailDTO> composeDetailListDTO(List<HswhRentalHouse> hswhRentalHouses) {
        List<HswhRentalHouseDetailDTO> hswhRentalHouseDetailDTO = new ArrayList<>();
        if (CollectionUtils.isEmpty(hswhRentalHouses)) {
            return hswhRentalHouseDetailDTO;
        }
        for (HswhRentalHouse DO : hswhRentalHouses) {
            HswhRentalHouseDetailDTO dto = new HswhRentalHouseDetailDTO();
            BeanUtils.copyProperties(DO, dto);
            hswhRentalHouseDetailDTO.add(dto);
        }
        return hswhRentalHouseDetailDTO;
    }


    public static HswhRentalHouseDetailDTO composeDetailDTO(HswhRentalHouse hswhRentalHouse) {
        HswhRentalHouseDetailDTO hswhRentalHouseDetailDTO = new HswhRentalHouseDetailDTO();
        if (null == hswhRentalHouse) {
            return hswhRentalHouseDetailDTO;
        }
        HswhRentalHouseDetailDTO dto = new HswhRentalHouseDetailDTO();
        BeanUtils.copyProperties(hswhRentalHouse, dto);
        return dto;
    }

    public static List<HswhRentalHouseListEntity> composeListEntity(List<HswhRentalHouse> list) throws Exception {
        List<HswhRentalHouseListEntity> dtoList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return dtoList;
        }
        for (HswhRentalHouse DO : list) {
            HswhRentalHouseListEntity dto = new HswhRentalHouseListEntity();
            BeanUtils.copyProperties(DO, dto);
            if (StringUtils.isNotBlank(DO.getImgs())){
                dto.setImg(true);
            }else {
                dto.setImg(false);
            }
            dtoList.add(dto);
        }
        return dtoList;
    }

    public static List<HswhRentalHouseListEntity> composeListEntity1(List<EsHswhRentalHouse> list) throws Exception {
        List<HswhRentalHouseListEntity> dtoList = new ArrayList<>();
        if (CollectionUtils.isEmpty(list)) {
            return dtoList;
        }
        for (EsHswhRentalHouse DO : list) {
            HswhRentalHouseListEntity dto = new HswhRentalHouseListEntity();
            BeanUtils.copyProperties(DO, dto);
            if("暂无".equals(dto.getHouseType()) || "暂无信息".equals(dto.getHouseType())){
                dto.setHouseType("");
            }
            if("暂无".equals(dto.getDirection()) || "暂无信息".equals(dto.getDirection())){
                dto.setDirection("");
            }
            if("0".equals(dto.getFloor())){
                dto.setFloor("");
            }
            if (StringUtils.isNotBlank(DO.getImgs())){
                dto.setImg(true);
            }else {
                dto.setImg(false);
            }
            dtoList.add(dto);
        }
        return dtoList;
    }
}
